package org.wattdepot.cli.command;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.Test;

/**
 * Tests the listSources method with various inputs for correct outputs.
 * 
 * @author Alex Kan and Kelvin Green
 * @version 2.0
 */
public class TestWattDepotListSources {

  WattDepotCommand commandInstance;
  String[] commandArray;
  String userInput;
  private static final String SOURCES = "sources";

  /**
   * Test WattDepotListSources for 2 correct outputs and errors on 2 inputs.
   * 
   * Test (correct) SOURCES: SIM_WAIAU Test (correct) SOURCES: Waiau 9 is a HECO plant on Oahu's
   * grid that uses diesel as its fuel. Test (error) SOURCES: SIM_WAIAU_11 Test (error) sources 1:
   * Correct command is sources
   */
  @Test
  public void testListSources() {
    WattDepotCommand.connect("http://server.wattdepot.org:8182/wattdepot/");
    commandInstance = new WattDepotListSourcesCommand();
    userInput = SOURCES;
    commandArray = userInput.split(" ");
    assertTrue("Check for SIM_WAIAU", 
        commandInstance.doCommand(commandArray).contains("SIM_WAIAU"));

    userInput = SOURCES;
    commandArray = userInput.split(" ");
    assertTrue("Check for SIM_WAIAU_9", commandInstance.doCommand(commandArray).contains(
        "Waiau 9 is a HECO plant on Oahu's grid that" + " uses diesel as its fuel."));

    userInput = SOURCES;
    commandArray = userInput.split(" ");
    assertFalse("Check for error", commandInstance.doCommand(commandArray)
        .contains("SIM_WAIAU_11."));

    userInput = "sources 1";
    commandArray = userInput.split(" ");
    assertTrue("Check for error", commandInstance.doCommand(commandArray).contains(
        "Correct command is sources"));

  }

}
